﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace ScormModel
{
    [Serializable()]
    public class Organizations
    {
        private string _default = "";
        private string _title ="";
        //adlseq:objectivesGlobalToSystem(optional, default = true)
        //adlcp:sharedDataGlobalToSystem (optional, default = true)
        private List<Organization> _listOrganization;
         [NonSerialized]
        private XmlNode _organizationsContent;
        [XmlAttribute("default")]
        public string Default
        {
            get { return this._default; }
            set { this._default = value; }
        }
        [XmlAttribute("title")]
        public string Title
        {
            get { return this._title; }
            set { this._title = value; }
        }
        [XmlElement("organization")]
        public List<Organization> ListOrganization
        {
            get { return this._listOrganization; }
            set { this._listOrganization = value; }
        }
        
        [XmlIgnoreAttribute]
        public XmlNode OrganizationsContent
        {
            get { return this._organizationsContent; }
            set { this._organizationsContent = value; }
        }
        public void buildOrganizations(string courseTemplate)
        {
            XmlAttributeCollection attList = _organizationsContent.Attributes;
            if (attList.GetNamedItem("default") != null)
            {
                _default = ((XmlAttribute)attList.GetNamedItem("default")).Value;
            }
            if (attList.GetNamedItem("title") != null)
            {
                _title = ((XmlAttribute)attList.GetNamedItem("title")).Value;
            }
            XmlNodeList childList = _organizationsContent.ChildNodes;
            _listOrganization = new List<Organization>();
            for (int i = 0; i < childList.Count; i++)
            {
                if (childList[i].Name == "organization")
                {

                    Organization organization = new Organization();
                    organization.OrganizationContent = childList[i];
                    organization.buildOrganization(courseTemplate);
                    _listOrganization.Add(organization);
                }
            }
        }
        public TreeViewItem createOrganizationsTreeViewItem()
        {
            if (_title == "")
                _title = "E-LearningCourse";
            TreeViewItem mainRootItem = TreeUtil.GetTreeView(_title, "BookIcon.png");
            for (int i = 0; i < _listOrganization.Count; i++)
            {
                TreeViewItem organizationItem = _listOrganization[i].createOrganizationTreeViewItem();
                mainRootItem.Items.Add(organizationItem);
            }
            return mainRootItem;
        }
        public  TreeViewItem initCustomCourse()
        {
            if (_title == "")
                _title = "E-LearningCourse";
            TreeViewItem mainRootItem = TreeUtil.GetTreeView(_title, "BookIcon.png");
            for (int i = 0; i < _listOrganization.Count; i++)
            {
                TreeViewItem organizationItem = TreeUtil.GetTreeView(_listOrganization[i].Title, "CourseIcon.png");
                mainRootItem.Items.Add(organizationItem);
            }
            return mainRootItem;
        }
    }
}
